<template>
	<view>
		<cu-custom bgColor="bg-red" :isBack="true">		<block slot="backText"></block>
			<block slot="content">{{config?config.interval_name:'-'}}转让</block>
		</cu-custom>

		<view class="bg-blue overflow padding-lg text-white text-center relative">
			<view class="margin-tb ">当前{{config?config.interval_name:'-'}}</view>
			<view class="text-xl text-bold ">{{member?member.account.user_integral:'-'}}</view>
		</view>

		<view class="cu-form-group ">
			<view class="title">转让金额</view>
			<input placeholder="转让数量" name="input" type="number" min="1" step="1" class="text-right" v-model="formData.num"></input>
		</view>
		<view class="cu-form-group ">
			<view class="title">用户ID</view>
			<input placeholder="用户" name="input" type="number" min="1" step="1" class="text-right" v-model="formData.to_member"></input>
		</view>
		<view class="cu-bar tabbar shadow foot " :class="['bg-'+theme,loading?'light':'']">
			<view class="submit text-lg" v-if="loading">
				<text class="cuIcon-loading2 cuIconfont-spin"></text>
				转让中
			</view>
			<view class="submit text-lg" @tap="submitApply" v-else>
				立即转让
			</view>
		</view>

		<view class="cu-modal" :class="modalName=='Modal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">请输入密码</view>
					<view class="action" @tap="modalName=''">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding">
					<view class="text-gray margin-bottom text-left">可在个人中心-设置里面修改密码<text @tap="goPage('/pages/member/password')" class="cu-btn line-blue margin-left-sm round sm ">去设置</text></view>
					<input placeholder="密码" type="password" name="input" v-model="formData.password" style="border: 1px solid #CCC; line-height: 40px; height: 40px;"></input>
					<view class="cu-btn bg-blue margin-top-xl lg radius" @tap="submit">
						<view class="submit text-lg" v-if="loading">
							<text class="cuIcon-loading2 cuIconfont-spin"></text>
							处理中
						</view>
						<view class="submit text-lg" @tap="submitApply" v-else>
							确定
						</view>
					</view>
				</view>
			</view>
		</view>

		<Foot :value="''"></Foot>
	</view>
</template>

<script>
	import Foot from '@/components/default/foot.vue'
	export default {
		components: {
			Foot,
		},
		data() {
			return {
				member: null,
				config: null,
				CLOUDPATH: this.$config.cloudPath,
				theme: this.$config.THEME(),
				payment_code: 'Wechat',
				loading: false,
				formData: {
					num: 0,
					to_member: 0,
					password: '',
				},
				modalName: '',
			}
		},
		onLoad(options) {
			if (this.$common.loginAuth(true)) {
				this.$common.getConfig().then((config) => {
					this.config = config
				})
				this.$common.getMember().then((member) => {
					this.member = member
				})
			}
		},
		onShow() {
			if (this.$common.loginAuth(true)) {}
		},
		methods: {
			submitApply() {
				let money = this.formData.num
				if (!money) {
					this.$common.showError('请输入数量')
					return
				}
				if (!this.formData.to_member) {
					this.$common.showError('请输入用户id')
					return
				}
				this.modalName = 'Modal'
			},
			submit() {
				if (!this.formData.password) {
					this.$common.showError('请输入密码')
					return
				}
				if (this.loading) return
				this.loading = true

				this.$http.post('integral_send', this.formData)
					.then((response) => {
						console.log(response)
						this.loading = false
						this.payLoading = false
						this.formData.password = ''
						this.$common.rmCache('member')
						this.$common.getMember().then((member) => {
							this.member = member
						})
						this.$common.showSuccess('处理成功',(r)=>{
							this.modalName = ''
						})
					})
					.catch((response) => {
						console.log((response))
						this.loading = false
						this.payLoading = false
					})

			}
		},
		onReachBottom() {
			this.getList()
		}
	}
</script>

<style>
	.txbtn {
		min-width: 160rpx;
	}

	.loglg {
		right: 0;
		top: 30rpx;
		border-radius: 30rpx 0 0 30rpx;
	}
</style>
